package com.senjoeson.socialsecure.ui;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.senjoeson.socialsecure.R;
import com.senjoeson.socialsecure.model.ReComment;
import com.senjoeson.socialsecure.utils.ParseUtils;

import butterknife.BindView;
import butterknife.ButterKnife;


public class CommentReviewActivity extends AppCompatActivity {


    private static final int UPDATE_UI = 0X01;
    @BindView(R.id.toolbar_title)
    TextView mToolbarTitle;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.which)
    TextView mWhich;
    @BindView(R.id.when)
    TextView mWhen;
    @BindView(R.id.title)
    TextView mTitle;
    @BindView(R.id.commentContent)
    TextView mCommentContent;
    @BindView(R.id.commentlistRV)
    RecyclerView mCommentlistRV;
    public ReComment mReComment;


    @SuppressLint("HandlerLeak")
    public Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
          switch (msg.what){
              case UPDATE_UI:
                  setData(mReComment);
                  break;
          }
        }
    };

    private void setData(ReComment reComment) {

        mTitle.setText(reComment.getTitle());
        mCommentContent.setText(reComment.getContent());
        mWhen.setText(reComment.getTime());
        mWhich.setText(reComment.getName());

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comment_review);
        ButterKnife.bind(this);
        String uuid = getIntent().getStringExtra("uuid");
        loadData(uuid);
    }

    private void loadData(final String uuid) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mReComment = ParseUtils.parseComment(uuid);
                mHandler.sendEmptyMessage(UPDATE_UI);
            }
        }).start();


    }
}
